package com.aaa.sbm.config;

import com.aaa.sbm.controller.GoodsController;
import com.aaa.sbm.controller.UserController;
import com.aaa.sbm.entity.EntityA;
import com.aaa.sbm.entity.EntityB;
import com.aaa.sbm.service.UserService;
import com.aaa.sbm.service.impl.UserServiceImpl;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @FileName: MyConfig
 * @Description:
 * @Author: zhz
 * @CreateTime: 2025/8/26 11:34
 * @Version: 1.0.0
 */
@Configuration  //定义bean源，过去xml配置一堆bean   相当于过去xml配置中beans <beans></beans>
//@SpringBootConfiguration
public class MyConfig {

    /**
     * 配置UserController
     * @return
     */
    @Bean("uc1")  //<bean id=uc1 class=com.aaa.sbm.controller.UserController>
    public UserController userController(){
        UserController userController = new UserController();
        userController.setUserService(userService());
        return userController;
    }

    /**
     * 配置UserServiceImpl
     * @return
     */
    @Bean //<bean id=userService class =com.aaa.sbm.service.impl.DeptServiceImpl >
    public UserServiceImpl userService(){
        UserServiceImpl userService = new UserServiceImpl();
        //UserService a = userService;
        return userService;
    }
    /**
     * 配置一个bean  EntityA
     * @return
     */

    @Bean("ea1")   //<bean id='ea1' class='com.aaa.sbm.entity.EntityA'>
    //@Bean   //<bean id='ea1' class='com.aaa.sbm.entity.EntityA'>
    //@Bean   //<bean id='entityA' class='com.aaa.sbm.entity.EntityA'>
    //public EntityA ea(){
    public EntityA entityA(){
        //实例化，返回
        EntityA entityA = new EntityA();
        //依赖注入
        entityA.setEntityB(entityB());
        return  entityA;
    }

    /**
     * 配置一个bean  EntityB
     * @return
     */

    @Bean   //<bean id='ea1' class='com.aaa.sbm.entity.EntityA'>
    public EntityB entityB(){
        //实例化，返回
        EntityB entityB = new EntityB();
        return  entityB;
    }

    /**
     * 配置GoodsController
     * @return
     */
    @Bean  //<bean id=goodsController class=com.aaa.sbm.controller.GoodsController>
    public GoodsController goodsController(){
        GoodsController goodsController =new GoodsController();
        return goodsController;
    }
}
